package com.learn.cloud.validator.annotation;

import com.learn.cloud.validator.constraints.PhoneValidator;
import jakarta.validation.Constraint;
import jakarta.validation.Payload;

import java.lang.annotation.*;

import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
 * @description: 电话号码校验
 * @author: cong zhi
 * @createDate: 2022/2/6 16:04
 * @updateUser: cong zhi
 * @updateDate: 2022/2/6 16:04
 * @updateRemark: 修改内容
 * @version: v1.0
 */
@Documented
@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = {PhoneValidator.class}) // 指定了当前注解使用哪个校验类来进行校验。
public @interface Phone {

    String message() default "手机号码格式有误!";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};

    /**
     * 是否必填
     * <p>
     * 如果必填，在校验的时候本字段没值就会报错
     */
    boolean required() default true;

    @Target({ElementType.FIELD, ElementType.PARAMETER})
    @Retention(RUNTIME)
    @Documented
    @interface List {
        Phone[] value();
    }
}
